package com.ham.facade.impl;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ham.facade.ItemReaderFacade;
import com.ham.model.ItemModel;

public class ItemCSVReaderFacadeImpl extends MainFacadeImpl implements
		ItemReaderFacade {
	private static final Logger LOGGER = LoggerFactory
			.getLogger(ItemCSVReaderFacadeImpl.class);

	@Override
	public List<ItemModel> getItemList(String filePath) throws IOException {
		LOGGER.debug("Start processing " + filePath);
		String line = "";
		String separator = ",";
		List<ItemModel> items = new ArrayList<ItemModel>();
		BufferedReader br = new BufferedReader(new FileReader(filePath));
		while ((line = br.readLine()) != null) {
			String[] lines = line.split(separator);
			ItemModel item = new ItemModel();
			item.setId(lines[0]);
			item.setName(lines[1]);
			item.setPurchaseDate(lines[2]);
			items.add(item);
		}
		items.remove(0);
		return items;
	}

}
